package ooday03.homework;

public class PolymorphicDemo {
    public static void main(String[] args) {

        //创建Animal数组并填充对象
        Animal[] animals = new Animal[6];
        animals[0] = new Dog("大黄", 2, "黄");
        animals[1] = new Dog("小白", 4, "白");
        animals[2] = new Fish("泡泡", 5, "红");
        animals[3] = new Fish("咕噜", 6, "金");
        animals[4] = new Chick("太美", 7, "棕");
        animals[5] = new Chick("黑子", 8, "黑");

        //遍历Animal数组
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            //父类共有行为
            animals[i].eat();
            animals[i].drink();
            //子类特有行为
            if (animals[i] instanceof Dog) {
               ((Dog) animals[i]).lookHome();
            }
            if (animals[i] instanceof Chick) {
                ((Chick) animals[i]).layEggs();
            }
            if (animals[i] instanceof Swim) {
                ((Swim) animals[i]).swim();
            }
        }

        //创建对象
        Master master = new Master();
        Dog dog = new Dog("小蝶", 5, "粉");
        Fish fish = new Fish("小花", 6, "花");
        Chick chick = new Chick("别急", 3, "褐");
        //调用master的feed(）方法
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);

    }
}
